Skip to content

Conversation

@jzhang20133
Copy link
Collaborator

server side should send awareness message every 15 seconds but that task is not turned on. This PR will turn it on. Server side awareness messages will keep the ydoc websocket alive even if client side stops sending awareness messages due to browser background tab throttling.
Addressing the following issue when browser tab is not focused on:
#115

@jzhang20133 jzhang20133 requested review from Zsailer and dlqqq and removed request for Zsailer and dlqqq June 26, 2025 00:41
@dlqqq dlqqq changed the title turn on server awareness messages to keep client websocket alive Start awareness heartbeat task to keep Websockets alive Jun 26, 2025
@dlqqq dlqqq added the enhancement New feature or request label Jun 26, 2025
Comment on lines -671 to -673
# Broadcast AwarenessUpdate message to all other synced clients
self._broadcast_message(message, message_type="AwarenessUpdate")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch Jialin, thank you for removing this & the condition in _on_awareness_update().

I had to check the pycrdt source code (Awareness._emit()) to figure out why your PR works. The two deleted portions of code were used together to handle broadcasting awareness updates in two areas; this was done following the original implementation in jupyter_collaboration. But by removing those 2 portions of code, all of the broadcasting is now done in _on_awareness_update(). Fantastic! 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key fix is to turn on server awareness message asyncio.create_task(self._awareness.start()), previously we did not kick start this task so a server generated awareness message (like a ping message to keep client side aware of its aliveness) are not sent every 15 seconds. And yes, you are right, removing the condition in _on_awareness_update() will allow those server awareness message to be broadcasted. Last, removing the broadcast call in handle_awareness_update method is to prevent a client awareness message for broadcasted twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing, @dlqqq !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server side awareness messages will keep the ydoc websocket alive even if client side stops sending awareness messages due to browser background tab throttling.

@jzhang20133 jzhang20133 merged commit 8bdfa7f into jupyter-ai-contrib:main Jun 26, 2025
4 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants